﻿using System;
using System.Diagnostics;
using System.Threading.Tasks;

namespace Daq.Utils
{
    internal class LicenseHelper
    {
		public static bool CheckLicense(out string id)
		{
			id = "";
#if !DEBUG
            if (IntelliLock.Licensing.CurrentLicense.License.LicenseStatus != IntelliLock.Licensing.LicenseStatus.Licensed)
			{
				id = GetCID();
				//MessageBox.Show($"软件未授权\n机器ID:{id}");
				//System.Environment.Exit(0);
				return false;
			}
			return true;
#else
			return true;
#endif
        }

		public static string GetCID()
		{
			return IntelliLock.Licensing.HardwareID.GetHardwareID(true, true, false, true, true, true);
        }

		public static async Task RestartApplication()
		{
            string currentExePath = System.Reflection.Assembly.GetEntryAssembly().Location;
            string fileNameWithoutExt = System.IO.Path.GetFileNameWithoutExtension(currentExePath);
            string newFilePath = System.IO.Path.ChangeExtension(fileNameWithoutExt, ".exe");
            Process.Start(newFilePath);
            await Task.Delay(500);
            Environment.Exit(0);
        }
    }
}
